using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using FlatRedBall;
using FlatRedBall.Graphics;
using FlatRedBall.Input;

using Like_a_bomberman.Screens;

namespace Like_a_bomberman
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        CollisionManager col = CollisionManager.getInstance();
        
        

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferHeight = 600;
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            Renderer.UseRenderTargets = false;
            FlatRedBallServices.InitializeFlatRedBall(this, graphics);

            //ScreenManager.Start(typeof(SomeScreen).FullName);

                     
            //col.AddRuleCollision(1, 2);
            col.AddRuleCollision(1, 3);
            col.AddRuleCollision(1, 4);

            Scene Scene = FlatRedBallServices.Load<Scene>("Nivel_1.scnx");

            foreach (Sprite block in Scene.Sprites.FindAllWithNameContaining("square"))
            {
                Bloque bloque_1 = new Bloque(this, block);
                this.Components.Add(bloque_1);
            }

            foreach (Sprite block in Scene.Sprites.FindAllWithNameContaining("bricks"))
            {
                Bloque_destructible bloque_2 = new Bloque_destructible(this, block);
                this.Components.Add(bloque_2);

            }

            //Sprite bloque = Scene.Sprites.FindByName("square3");
            //Sprite bloque_2 = Scene.Sprites.FindByName("square4");

            //bloque.YVelocity = 8;
            //bloque.YAcceleration = -4;
            //bloque.XVelocity = -8;
            //bloque.XAcceleration = 3;

            //bloque_2.YVelocity = 8;
            //bloque_2.YAcceleration = -4;
            //bloque_2.XVelocity = 8;
            //bloque_2.XAcceleration = -3;


            Jugador bomberman = new Jugador(this);
            this.Components.Add(bomberman);

            //Sprite ene = Scene.Sprites.FindByName("enemigo1");
            //Enemigo_ip Enemy = new Enemigo_ip(this, ene, bomberman);
            //this.Components.Add(Enemy);


            


             Scene.AddToManagers();

          

            base.Initialize();
              //
        }


        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            
            FlatRedBallServices.Update(gameTime);

            ScreenManager.Activity();

           

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            col.Update();
            
            FlatRedBallServices.Draw();
            
            base.Draw(gameTime);

           



        }
    }
}
